/*
 *  Copyright (C) 2020 original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License
 *  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 *  or implied. See the License for the specific language governing permissions and limitations under
 *  the License.
 */

package vip.justlive.easyproxy.core.protocol;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 消息类型
 *
 * @author wubo
 */
@Getter
@RequiredArgsConstructor
public enum ProxyDataType {
  /**
   * 心跳
   */
  BEAT(-1),
  /**
   * 校验
   */
  AUTH(1),
  /**
   * 创建连接
   */
  CONNECT(2),
  /**
   * 传输
   */
  TRANSFER(3),
  /**
   * 关闭channel
   */
  CLOSE_CHANNEL(4),
  /**
   * 关闭proxy
   */
  CLOSE_PROXY(5),
  /**
   * 关闭client
   */
  CLOSE(6);

  private final int value;

  public static ProxyDataType from(int type) {
    for (ProxyDataType dataType : values()) {
      if (dataType.value == type) {
        return dataType;
      }
    }
    return null;
  }
}
